package org.zwd.computePrice.action;

import org.zwd.computePrice.domain.CrabPrice;
import org.zwd.computePrice.service.CrabPriceService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class CrabPriceAction extends ActionSupport{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private int isOrder;
	private int malecrabids[];
	private int femalecrabids[];
	private double femaleprices[];
	private double maleprices[];
	private CrabPriceService crabPriceService = new CrabPriceService();
	
	
	public String update() throws Exception{
		
		for(int i = 0;i<maleprices.length;i++ ){
			CrabPrice crabPrice = new CrabPrice();
			crabPrice.setPrice(maleprices[i]);
			crabPrice.setCrabid(malecrabids[i]);
			crabPrice.setIsOrder(isOrder);
			//System.out.println(crabPrice);
			crabPriceService.appendPrice(crabPrice);
		}
		
		for(int i = 0;i<femaleprices.length;i++ ){
			CrabPrice crabPrice = new CrabPrice();
			crabPrice.setPrice(femaleprices[i]);
			crabPrice.setCrabid(femalecrabids[i]);
			crabPrice.setIsOrder(isOrder);
			//System.out.println(crabPrice);
			crabPriceService.appendPrice(crabPrice);
		}
		
		ActionContext.getContext().put("isOrder", isOrder);
		return "update";
		
	}


	
	public int[] getMalecrabids() {
		return malecrabids;
	}



	public void setMalecrabids(int[] malecrabids) {
		this.malecrabids = malecrabids;
	}



	public int[] getFemalecrabids() {
		return femalecrabids;
	}



	public void setFemalecrabids(int[] femalecrabids) {
		this.femalecrabids = femalecrabids;
	}



	public double[] getFemaleprices() {
		return femaleprices;
	}


	public void setFemaleprices(double[] femaleprices) {
		this.femaleprices = femaleprices;
	}


	public double[] getMaleprices() {
		return maleprices;
	}


	public void setMaleprices(double[] maleprices) {
		this.maleprices = maleprices;
	}

	public int getIsOrder() {
		return isOrder;
	}

	public void setIsOrder(int isOrder) {
		this.isOrder = isOrder;
	}


}
